// http://poj.org/problem?id=1458
// https://www.acwing.com/problem/content/6020/

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const int MAX_N = 1005;
int dp[MAX_N][MAX_N];
char X[MAX_N], Y[MAX_N];

int main() {
    while (scanf("%s %s", X, Y) != EOF) {
        const int len1 = strlen(X), len2 = strlen(Y);
        for (int i = 0; i < len1; i++) {
            dp[i][0] = 0;
        }
        for (int j = 0; j < len2; j++) {
            dp[0][j] = 0;
        }

        for (int i = 1; i <= len1; i++) {
            for (int j = 1; j <= len2; j++) {
                if (X[i - 1] == Y[j - 1]) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                } else {
                    dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
                }
            }
        }

        printf("%d\n", dp[len1][len2]);
    }
    return 0;
}

